package dao;

import entity.OrderInfo;
import openConn.DruidUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class OrderDao {
    public static int insert (OrderInfo orderInfo) throws SQLException {
        Connection connection = DruidUtils.openConn();
        String sql = "insert into order_info(user_id,com_id,address_id,buy_count) values (?,?,?,?)";
        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setInt(1,orderInfo.getUserId() );
        statement.setInt(2,orderInfo.getComId());
        statement.setInt(3,orderInfo.getAddressId());
        statement.setDouble(4,orderInfo.getBuyCount());
        int count = statement.executeUpdate();
        statement.close();
        connection.close();
        return count;
    }
    public static int insert (OrderInfo orderInfo,Connection connection) throws SQLException {

        String sql = "insert into order_info(user_id,com_id,address_id,buy_count) values (?,?,?,?)";
        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setInt(1,orderInfo.getUserId() );
        statement.setInt(2,orderInfo.getComId());
        statement.setInt(3,orderInfo.getAddressId());
        statement.setDouble(4,orderInfo.getBuyCount());
        int count = statement.executeUpdate();
        statement.close();
        return count;
    }
}
